<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<title>请求新增</title>
	<link href="/lib/pearadmin/component/pear/css/pear.css" rel="stylesheet">
	<link href="/css/sitesmanager.css" rel="stylesheet">
</head>
<body class="pear-container">
	<div class="body-card layui-card padding">
		<form id="saveForm" class="layui-form" action="javascript:void(0);">
			<div class="layui-form-item">
				<label class="layui-form-label"><span class="color-warn">*</span>
					资源类型</label>
				<div class="layui-input-block">
					<input type="radio" name="type" value="1" title="菜单" lay-verify="required">
					<input type="radio" name="type" value="2" title="按钮" lay-verify="required">
					<input type="radio" name="type" value="3" title="接口" lay-verify="required">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span class="color-warn">*</span>
					父节点</label>
				<div class="layui-input-inline">
					<select name="parent" lay-verify="required">
						<option value="0">一级菜单</option>
						<option th:each="a : ${actionList}" th:value="${a.id}" th:text="${a.title}"></option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span class="color-warn">*</span>
					请求标题</label>
				<div class="layui-input-inline">
					<input type="text" name="title" placeholder="请输入标题" lay-verify="required" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">图标</label>
				<div class="layui-input-inline">
					<button class="pear-btn"> 请选择图标 </button>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label"><span class="color-warn">*</span>请求地址</label>
				<div class="layui-input-block">
					<input type="text" name="actionKey" value="" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-input-block">
					<button type="button" class="pear-btn pear-btn-primary" lay-submit lay-filter="saveForm">立即提交</button>
					<button type="reset" class="pear-btn">重置</button>
				</div>
			</div>
		</form>
	</div>
	
	<script src="/lib/pearadmin/component/layui/layui.js"></script>
	<script src="/lib/pearadmin/component/pear/pear.js"></script>
	<script>
		layui.use([ 'form', 'element', 'popup'], function() {
			let form = layui.form;
			let element = layui.element;
			let popup = layui.popup;
			let $ = layui.$;//使用layui内置的jQuery
			
			//表单提交
			form.on('submit(saveForm)', function(data) {
				// 验证：表单字段设置属性，自动验证
				// 提交
				let $form = $("#saveForm");
				$.post("/action/saveAction", $form.serialize(), function(data){
					if("1"==data.state){
						popup.success("保存成功", function() {
							//当你在iframe页面关闭自身时
							let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
							parent.layer.close(index); //再执行关闭
						});
					} else {
						popup.failure(data.msg);
					}
				});
				return false;
			});
		});
	</script>
</body>
</html>
